/*
 * Copyright (c) 2016. Naivor.All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.myapplication.base;


import com.example.myapplication.base.network.NetWorkManager;
import retrofit2.Retrofit;

/**
 * BaseRepository app的数据仓库类，所有需要的数据都通过它获得仓库
 * <p/>
 */

public abstract class BaseRepository<T> {
    protected static final String TAG = "BaseRepository";

    protected Retrofit retrofit;

    protected T apiServer;

    //对于列表,每页显示的内容条数
    public static final int pageSum = 10;

    public BaseRepository() {
        this.retrofit = NetWorkManager.getInstance().getRetrofit();
    }



    /**
     * 获取接口对象
     */
    protected T getServer() {
        if (apiServer == null) {
            final Class<T> c = defServiceType();

            if (c == null) {
                throw new NullPointerException("ApiServer 的类型不能为 null");
            }

            apiServer = retrofit.create(c);
        }

        return apiServer;
    }

    /**
     * 定义接口类型
     *
     * @return
     */
    protected abstract Class<T> defServiceType();


}
